package com.ybkj.o2o.zhuanche.thrift;

import org.apache.thrift.EncodingUtils;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;
import org.apache.thrift.scheme.TupleScheme;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Generated;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-12-05")
public class IdResult implements org.apache.thrift.TBase<IdResult, IdResult.Fields>,
    java.io.Serializable, Cloneable, Comparable<IdResult> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC =
      new org.apache.thrift.protocol.TStruct("IdResult");

  private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC =
      new org.apache.thrift.protocol.TField(
          "code", org.apache.thrift.protocol.TType.I32, (short) 1);
  private static final org.apache.thrift.protocol.TField ID_FIELD_DESC =
      new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.I64, (short) 2);
  private static final org.apache.thrift.protocol.TField MSG_FIELD_DESC =
      new org.apache.thrift.protocol.TField("msg", org.apache.thrift.protocol.TType.STRING,
          (short) 3);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes =
      new HashMap<Class<? extends IScheme>, SchemeFactory>();
  
  static {
    schemes.put(StandardScheme.class, new IdResultStandardSchemeFactory());
    schemes.put(TupleScheme.class, new IdResultTupleSchemeFactory());
  }

  public int code; // required
  public long id; // required
  public String msg; // optional

  /**
   * The set of fields this struct contains, along with convenience methods for finding and
   * manipulating them.
   */
  public enum Fields implements org.apache.thrift.TFieldIdEnum {
    CODE((short) 1, "code"), ID((short) 2, "id"), MSG((short) 3, "msg");

    private static final Map<String, Fields> byName = new HashMap<String, Fields>();

    static {
      for (Fields field : EnumSet.allOf(Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the Fields constant that matches fieldId, or null if its not found.
     */
    public static Fields findByThriftId(int fieldId) {
      switch (fieldId) {
        case 1: // CODE
          return CODE;
        case 2: // ID
          return ID;
        case 3: // MSG
          return MSG;
        default:
          return null;
      }
    }

    /**
     * Find the Fields constant that matches fieldId, throwing an exception if it is not found.
     */
    public static Fields findByThriftIdOrThrow(int fieldId) {
      Fields fields = findByThriftId(fieldId);
      if (fields == null) {
        throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      }
      return fields;
    }

    /**
     * Find the Fields constant that matches name, or null if its not found.
     */
    public static Fields findByName(String name) {
      return byName.get(name);
    }

    private final short thriftId;
    private final String fieldName;

    Fields(short thriftd, String fieldname) {
      thriftId = thriftd;
      fieldName = fieldname;
    }

    public short getThriftFieldId() {
      return thriftId;
    }

    public String getFieldName() {
      return fieldName;
    }
  }

  // isset id assignments
  private static final int __CODE_ISSET_ID = 0;
  private static final int __ID_ISSET_ID = 1;
  private byte issetBitfield = 0;
  public static final Map<Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  
  static {
    Map<Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap =
        new EnumMap<Fields, org.apache.thrift.meta_data.FieldMetaData>(Fields.class);
    tmpMap.put(Fields.CODE, new org.apache.thrift.meta_data.FieldMetaData("code",
        org.apache.thrift.TFieldRequirementType.DEFAULT,
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
    tmpMap.put(Fields.ID, new org.apache.thrift.meta_data.FieldMetaData("id",
        org.apache.thrift.TFieldRequirementType.DEFAULT,
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
    tmpMap.put(Fields.MSG,
        new org.apache.thrift.meta_data.FieldMetaData("msg",
            org.apache.thrift.TFieldRequirementType.OPTIONAL,
            new org.apache.thrift.meta_data.FieldValueMetaData(
                org.apache.thrift.protocol.TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(IdResult.class, metaDataMap);
  }

  public IdResult() {
    this.code = 0;

  }

  /**
   * 设置.
   */
  public IdResult(int code, long id) {
    this();
    this.code = code;
    setCodeIsSet(true);
    this.id = id;
    setIdIsSet(true);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public IdResult(IdResult other) {
    issetBitfield = other.issetBitfield;
    this.code = other.code;
    this.id = other.id;
    if (other.isSetMsg()) {
      this.msg = other.msg;
    }
  }

  public IdResult deepCopy() {
    return new IdResult(this);
  }

  @Override
  public void clear() {
    this.code = 0;

    setIdIsSet(false);
    this.id = 0;
    this.msg = null;
  }

  public int getCode() {
    return this.code;
  }

  /**
   * 设置值.
   */
  public IdResult setCode(int code) {
    this.code = code;
    setCodeIsSet(true);
    return this;
  }

  public void unsetCode() {
    issetBitfield = EncodingUtils.clearBit(issetBitfield, __CODE_ISSET_ID);
  }

  /** 
   * Returns true if field code is set (has been assigned a value) and false otherwise.
   */
  public boolean isSetCode() {
    return EncodingUtils.testBit(issetBitfield, __CODE_ISSET_ID);
  }

  public void setCodeIsSet(boolean value) {
    issetBitfield = EncodingUtils.setBit(issetBitfield, __CODE_ISSET_ID, value);
  }

  public long getId() {
    return this.id;
  }

  /**
   * 设置id.
   */
  public IdResult setId(long id) {
    this.id = id;
    setIdIsSet(true);
    return this;
  }

  public void unsetId() {
    issetBitfield = EncodingUtils.clearBit(issetBitfield, __ID_ISSET_ID);
  }

  /**
   * Returns true if field id is set (has been assigned a value) and false otherwise.
   */
  public boolean isSetId() {
    return EncodingUtils.testBit(issetBitfield, __ID_ISSET_ID);
  }

  public void setIdIsSet(boolean value) {
    issetBitfield = EncodingUtils.setBit(issetBitfield, __ID_ISSET_ID, value);
  }

  public String getMsg() {
    return this.msg;
  }

  public IdResult setMsg(String msg) {
    this.msg = msg;
    return this;
  }

  public void unsetMsg() {
    this.msg = null;
  }

  /** 
   * Returns true if field msg is set (has been assigned a value) and false otherwise.
   */
  public boolean isSetMsg() {
    return this.msg != null;
  }

  /**
   * 为false则返回空.
   */
  public void setMsgIsSet(boolean value) {
    if (!value) {
      this.msg = null;
    }
  }

  /**
   * 设置字段值.
   */
  public void setFieldValue(Fields field, Object value) {
    switch (field) {
      case CODE:
        if (value == null) {
          unsetCode();
        } else {
          setCode((Integer) value);
        }
        break;

      case ID:
        if (value == null) {
          unsetId();
        } else {
          setId((Long) value);
        }
        break;

      case MSG:
        if (value == null) {
          unsetMsg();
        } else {
          setMsg((String) value);
        }
        break;

      default:
    }
  }

  /**
   * 获取字段值.
   */
  public Object getFieldValue(Fields field) {
    switch (field) {
      case CODE:
        return getCode();

      case ID:
        return getId();

      case MSG:
        return getMsg();

      default:
    }
    throw new IllegalStateException();
  }

  /**
   * Returns true if field corresponding to fieldID is set (has been assigned a value) and false.
   * otherwise
   */
  public boolean isSet(Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
      case CODE:
        return isSetCode();
      case ID:
        return isSetId();
      case MSG:
        return isSetMsg();
      default:
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null) {
      return false;
    }
    if (that instanceof IdResult) {
      return this.equals((IdResult) that);
    }
    return false;
  }

  /**
   * 比较.
   */
  public boolean equals(IdResult that) {
    if (that == null) {
      return false;
    }
    boolean thisPresentCode = true;
    boolean thatPresentCode = true;
    if (thisPresentCode || thatPresentCode) {
      if (!(thisPresentCode && thatPresentCode)) {
        return false;
      }
      if (this.code != that.code) {
        return false;
      }
    }

    boolean thisPresentId = true;
    boolean thatPresentId = true;
    if (thisPresentId || thatPresentId) {
      if (!(thisPresentId && thatPresentId)) {
        return false;
      }
      if (this.id != that.id) {
        return false;
      }
    }

    boolean thisPresentMsg = true && this.isSetMsg();
    boolean thatPresentMsg = true && that.isSetMsg();
    if (thisPresentMsg || thatPresentMsg) {
      if (!(thisPresentMsg && thatPresentMsg)) {
        return false;
      }
      if (!this.msg.equals(that.msg)) {
        return false;
      }
    }

    return true;
  }

  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean presentCode = true;
    list.add(presentCode);
    if (presentCode) {
      list.add(code);
    }
    boolean presentId = true;
    list.add(presentId);
    if (presentId) {
      list.add(id);
    }
    boolean presentMsg = true && (isSetMsg());
    list.add(presentMsg);
    if (presentMsg) {
      list.add(msg);
    }
    return list.hashCode();
  }

  @Override
  public int compareTo(IdResult other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetCode()).compareTo(other.isSetCode());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetCode()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetId()).compareTo(other.isSetId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, other.id);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetMsg()).compareTo(other.isSetMsg());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetMsg()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.msg, other.msg);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public Fields fieldForId(int fieldId) {
    return Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) 
      throws org.apache.thrift.TException {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) 
      throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("IdResult(");
    boolean first = true;

    sb.append("code:");
    sb.append(this.code);
    first = false;
    if (!first) {
      sb.append(", ");
    }
    sb.append("id:");
    sb.append(this.id);
    first = false;
    if (isSetMsg()) {
      if (!first) {
        sb.append(", ");
      }
      sb.append("msg:");
      if (this.msg == null) {
        sb.append("null");
      } else {
        sb.append(this.msg);
      }
      first = false;
    }
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(
          new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException,
      ClassNotFoundException {
    try {
      // it doesn't seem like you should have to do this, but java serialization is wacky, and
      // doesn't call the default constructor.
      issetBitfield = 0;
      read(new org.apache.thrift.protocol.TCompactProtocol(
          new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class IdResultStandardSchemeFactory implements SchemeFactory {
    public IdResultStandardScheme getScheme() {
      return new IdResultStandardScheme();
    }
  }

  private static class IdResultStandardScheme extends StandardScheme<IdResult> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, IdResult struct)
        throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true) {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
          break;
        }
        switch (schemeField.id) {
          case 1: // CODE
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.code = iprot.readI32();
              struct.setCodeIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // ID
            if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
              struct.id = iprot.readI64();
              struct.setIdIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // MSG
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.msg = iprot.readString();
              struct.setMsgIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, IdResult struct)
        throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      oprot.writeFieldBegin(CODE_FIELD_DESC);
      oprot.writeI32(struct.code);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(ID_FIELD_DESC);
      oprot.writeI64(struct.id);
      oprot.writeFieldEnd();
      if (struct.msg != null) {
        if (struct.isSetMsg()) {
          oprot.writeFieldBegin(MSG_FIELD_DESC);
          oprot.writeString(struct.msg);
          oprot.writeFieldEnd();
        }
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class IdResultTupleSchemeFactory implements SchemeFactory {
    public IdResultTupleScheme getScheme() {
      return new IdResultTupleScheme();
    }
  }

  private static class IdResultTupleScheme extends TupleScheme<IdResult> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, IdResult struct)
        throws org.apache.thrift.TException {
      BitSet optionals = new BitSet();
      if (struct.isSetCode()) {
        optionals.set(0);
      }
      if (struct.isSetId()) {
        optionals.set(1);
      }
      if (struct.isSetMsg()) {
        optionals.set(2);
      }
      TTupleProtocol oprot = (TTupleProtocol) prot;
      oprot.writeBitSet(optionals, 3);
      if (struct.isSetCode()) {
        oprot.writeI32(struct.code);
      }
      if (struct.isSetId()) {
        oprot.writeI64(struct.id);
      }
      if (struct.isSetMsg()) {
        oprot.writeString(struct.msg);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, IdResult struct)
        throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(3);
      if (incoming.get(0)) {
        struct.code = iprot.readI32();
        struct.setCodeIsSet(true);
      }
      if (incoming.get(1)) {
        struct.id = iprot.readI64();
        struct.setIdIsSet(true);
      }
      if (incoming.get(2)) {
        struct.msg = iprot.readString();
        struct.setMsgIsSet(true);
      }
    }
  }

}
